﻿using System;
using Glue;
using Xunit;

namespace GlueTests.RelationsVerificationTests
{
    public class When_a_relation_is_only_one_direction
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;
        private readonly IRelationsVerification verification;

        public class DomainPerson { public String FirstName { get; set; } }

        public class GuiPerson { public String FirstName { get; set; } }

        public When_a_relation_is_only_one_direction()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.RelateTowardsLeft(domain=>domain.FirstName,gui=>gui.FirstName);
            verification = mapping.GetRelationsVerification();
        }

        [Fact]
        public void Should_verify_the_relation_direction()
        {
            verification.AssertAllPropertiesRelated<DomainPerson>();
        }

        [Fact]
        public void Should_not_verify_the_other_direction()
        {
            Assert.Throws(typeof(GlueException),()=> verification.AssertAllPropertiesRelated<GuiPerson>());
        }

        [Fact]
        public void Should_verify_the_other_direction_if_that_direction_is_ignored()
        {
            mapping.IgnoreTowards<GuiPerson>(gui=>gui.FirstName);
            verification.AssertAllPropertiesRelated<GuiPerson>();
        }
    }
}
